<template>
  <div class="box2">
    <div class="title">
      <p>访问来源</p>
      <img src="../../images/dataScreen-title.png" alt="">
    </div>
    <!-- 图形图标的容器 -->
    <div class="charts" ref="charts"></div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'
const charts = ref(null)
onMounted(() => {
  // 基于准备好的dom，初始化echarts实例
  const myChart = echarts.init(charts.value)
  // 绘制图表
  myChart.setOption({
    title: {
      text: '用户访问来源',
      left: 'center',
      textStyle: {
        color: 'skyblue'
      }
    },
    tooltip: {
      trigger: 'item',
      formatter: '{a} <br/>{b} : {c} ({d}%)'
    },
    toolbox: {
      show: true,
      feature: {
        dataView: { show: true, readOnly: false },
        restore: { show: true },
        saveAsImage: { show: true }
      }
    },
    legend: {
      right: 30,
      top: 40,
      orient: 'vertical',//图例组件方向的设置
      textStyle: {
        color: 'white',
        fontSize: 14
      }
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: ['40%', '70%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: '#f0f0f0',
          borderWidth: 1
        },
        label: {
          show: true,
          position: 'inside',
          color: 'white'
        },
        labelLine: {
          show: false
        },
        data: [
          { value: 1048, name: '直接访问' },
          { value: 735, name: '视频广告' },
          { value: 580, name: '搜索引擎' },
          { value: 484, name: '百度网站' },
          { value: 300, name: '其他来源' }
        ]
      }
    ],
    // color: ['#675bba', '#f7b731', '#45c08b', '#f44336', '#9c27b0']
  })
})

</script>


<style scoped lang="less">
.box2 {
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-cb.png) no-repeat;
  background-size: 100% 100%;

  .title {
    margin-left: 20px;

    p {
      color: white;
      font-size: 20px;
    }
  }

  .charts {
    height: 300px;
  }
}
</style>